package com.shijie.newvideo;

import android.os.Bundle;
import android.os.Parcelable;
import android.view.View;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentPagerAdapter;

import com.shijie.newvideo.pagerslidingtabstrip.MyViewPager;

import java.util.ArrayList;
import java.util.List;

public class HomeMarketFragment extends BaseFragment {
    private static HomeMarketFragment instance = null;
    MyViewPager mViewPager;
    PagerSlidingTabStrip indicator;
    private ArrayList<String> titleList = new ArrayList<String>();
    private List<Fragment> fragmentList = new ArrayList<>();


    public static HomeMarketFragment newInstance() {
        if (instance == null) {
            instance = new HomeMarketFragment();
        }
        return instance;
    }

    @Override
    public View initView() {
        mview = View.inflate(context, R.layout.activity_home_market, null);
        indicator = mview.findViewById(R.id.indicator);
        mViewPager = mview.findViewById(R.id.pager);
        return mview;
    }
    private Fragment fragment1;
    private Fragment fragment2;
    @Override
    public void initData() {
        fragmentList.clear();
        titleList.clear();

        titleList.add("全部");
        titleList.add("222222");

        fragment1 = OrderListFragment.newInstance(null);
        fragment2 = OrderListFragment.newInstance("2");

        fragmentList.add(fragment1);
        fragmentList.add(fragment2);

        FragmentPagerAdapter adapter = new FragmentPagerAdapter(getChildFragmentManager()) {

            @Override
            public int getCount() {
                return fragmentList.size();
            }

            @Override
            public Fragment getItem(int position) {
                return fragmentList.get(position);
            }

            @Override
            public CharSequence getPageTitle(int position) {
                return titleList.get(position);
            }

            @Override
            public void restoreState(Parcelable state, ClassLoader loader) {
                super.restoreState(state, loader);
            }

        };

        mViewPager.setAdapter(adapter);
        indicator.setViewPager(mViewPager);

    }


}
